import { UserRuleForm, PhoneCodeForm, PhoneRuleForm, ILoginRequest } from '@interface/login'
import http from '@utils/request'

// 图形验证码
export function captchaImage(params: { key: string }): Promise<ArrayBuffer> {
  return http.get<ArrayBuffer>('/captcha/image', params, { responseType: 'arraybuffer' })
}

// 用户登录
export function loginByJson(data: UserRuleForm): Promise<ILoginRequest> {
  return http.post<ILoginRequest>('/u/loginByJson', data)
}

// 发送短信验证码
export function loginCaptcha(params: PhoneCodeForm): Promise<ILoginRequest> {
  return http.get<ILoginRequest>('/captcha/sendRegisterOrLoginCaptcha', params)
}

// 手机验证码登录
export function loginByMobile(data: PhoneRuleForm): Promise<ILoginRequest> {
  return http.post<ILoginRequest>('/u/loginByMobile', data)
}
